import pygame
import sys
import shape as c_shape


def game_over():
    pygame.quit()
    sys.exit()


def game_start():
    window_title = 'tetris'
    window_size = (300, 640)
    grid_num = (15, 32)  # 15列，32行
    grid_size = (20, 20)

    pygame.init()
    pg_clock = pygame.time.Clock()

    main_window = pygame.display.set_mode(window_size)
    pygame.display.set_caption(window_title)

    SHAPE = c_shape.SHAPE(grid_num)

    while True:

        for event in pygame.event.get():

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    SHAPE.rota_shape()
                elif event.key == pygame.K_DOWN:
                    pass
                elif event.key == pygame.K_LEFT:
                    SHAPE.move_step('left')
                elif event.key == pygame.K_RIGHT:
                    SHAPE.move_step('right')

            elif event.type == pygame.QUIT:
                game_over()

        SHAPE.move_step('down')

        main_window.fill((0, 0, 0))
        SHAPE.draw_shape(main_window, grid_size, )
        pygame.display.update()
        pg_clock.tick(10)


if __name__ == '__main__':
    game_start()
